package com.governtalk.backend.config;

import com.governtalk.backend.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
public class FileCleanupConfig {

    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 每小时清理一次临时文件
     */
    @Scheduled(fixedRate = 3600000) // 1小时 = 3600000毫秒
    public void cleanupTempFiles() {
        System.out.println("=== 定时清理临时文件任务开始 ===");
        try {
            fileUploadService.cleanupTempFiles();
            System.out.println("=== 定时清理临时文件任务完成 ===");
        } catch (Exception e) {
            System.err.println("=== 定时清理临时文件任务失败 ===");
            e.printStackTrace();
        }
    }
}

